<template>
	<!-- 取消之前的 确认发货 -->
	<view class="">
		<view class="delivery-courier" v-if="false">
			<view class="courier-number">
				<span>发货数量</span>
				<radio-group @change="radioChange" class="radio-group">
					<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
						<view class="radio">
							<radio :value="item.value" :checked="index === current" color="#077840" />
						</view>
						<view class="name">{{item.name}}</view>
					</label>
				</radio-group>
			</view>
			<view class="courier-box" v-if="orderType === 10">
				<view class="courier order-num">
					<span> 快递单号</span>
					<input type="text" v-model="express_order" placeholder="请填写快递单号" />
				</view>
				<view class="courier">
					<span class='comp'> 快递公司</span>
					<picker @change="bindPickerChange" :value="index" :range="array" :range-key="'value'">
						<view class="uni-input">{{bindPickers(array,index)}}</view>
					</picker>
				</view>
			</view>
			<!-- 部分发货。显示商品 -->
			<view class="split-line"></view>
			<view class="goods_detail" v-show="!diliform.allDelivery">
				<view class="goods_detail_item" v-for="(item,index) in orderProduct " :key='index'>
					<text class="goods_detail_item_order_title">订单商品</text>
					<text class="goods_detail_item_gooods_name">{{item.productName}}，
						{{item.productAttr}}</text>
					<text class="goods_detail_item_shipments_number">发货数量</text>
					<input class="goods_detail_item_shipments_import" type="number" v-model="item.num"
						placeholder="请输入发货数量" />
					<text class="goods_detail_item_extra">剩余数量</text>
					<text class="goods_detail_item_extra_number">{{item.sysl}}</text>
				</view>
			</view>

			<view class="next-btn" @click="submit">
				提交
			</view>
		</view>
		<view class="delivery-courier" v-if="isShowAll">
			<view class="popup-add-box">
				<uni-forms ref="baseForm" label-width="200rpx"  label-align='right' :modelValue="orderFrom">
					<uni-forms-item label="发货单号" required >
						<uni-easyinput :clearable='false' readonly disabled  v-model="orderFrom.deliveryNo" placeholder="请输入发货单号" />
					</uni-forms-item>
					<uni-forms-item label="发货日期" required >
						<!-- <uni-datetime-picker :clear-icon="false" disabled readonly type="datetime" return-type="timestamp"
							v-model="orderFrom.deliveryTime" /> -->
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.deliveryTime" />
					</uni-forms-item>

					<uni-forms-item label="发货方式" required >
						<!-- <uni-data-select :clear='false' v-model="orderFrom.deliveryType" :localdata="deliveryTypeRange"
							placeholder="请选择发货方式"></uni-data-select> -->
							<uni-easyinput :clearable='false' readonly disabled value="门店自提" placeholder="请输入发货单号" />
							
					</uni-forms-item>
					<uni-forms-item label="发货人" required >
						<!-- <uni-data-select v-model="orderFrom.deliveryUserName" :localdata="deliveryUserNameRange"
							placeholder="请选择发货人"></uni-data-select> -->
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.deliveryUserName" placeholder="请选择发货人" />
					</uni-forms-item>
					<uni-forms-item label="客户名称" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.extractName" placeholder="请输入发货单号" />
					</uni-forms-item>
					<uni-forms-item label="销售订单号" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.orderNo" placeholder="请输入销售订单号" />
					</uni-forms-item>
					<uni-forms-item label="订单总金额" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.orderPrice" placeholder="请输入订单总金额" />
					</uni-forms-item>
					<uni-forms-item label="优惠总金额" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.couponMoney" placeholder="请输入优惠总金额" />
					</uni-forms-item>
					<uni-forms-item label="发货总金额" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.deliveryBeforeAmount"/>
					</uni-forms-item>
					<uni-forms-item label="扣减补位金额" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.depositOutPrice"/>
					</uni-forms-item>
					<uni-forms-item label="本次发货总金额" required >
						<uni-easyinput :clearable='false' readonly disabled v-model="orderFrom.deliveryTotalAmount"/>
					</uni-forms-item>
				</uni-forms>
				<uni-section title="发货单明细" type="line">
					<template v-slot:right>
						<!-- 新增商品 -->
						<uni-icons class="icons-text" style="color: #077840;" type="plusempty" size="30"
							@click="addGoods"></uni-icons>
					</template>
					<uni-list>
						<uni-list-item thumb-size="lg" v-for="(val,index) in orderProduct" :key="index">
							<template v-slot:body>
								<view class="slot-box">
									<view class="slot-box-left">
										<img :src="val.imagePath" alt="" />
									</view>
									<view class="slot-box-right">
										<text class="slot-text">商品名称：{{val.productName}}</text>
										<view class="slot-text" style="display: flex;align-items: center;">
											<view>
												发货数量：
											</view>
											<view>
												<uni-easyinput style="width:70px;display: inline-block;margin-right: 10px;"
													:clearable='false' :disabled="val.isEdit" v-model="val.deliveryCount"
													placeholder="请输入发货数量" @change="selCount(val)" />
													<uni-data-select :disabled="val.isEdit" @change="selCount(val)" style="width: 150rpx;display: inline-block;" filterable :clear='false' v-model="val.orderProductType" :localdata="orderProductTypeList"
														placeholder="商品类型"></uni-data-select>
												<!-- <uni-number-box :disabled="val.isEdit" @change="selCount(val)" :min="0"
													:max="val.stockNum" v-model="val.deliveryCount" /> -->
											</view>
										</view>
										<view class="slot-text" style="display: flex;align-items: center;">
											<view>
												发货备注：
											</view>
											<view>
												<uni-easyinput
													style="width: 320rpx;display: inline-block;margin-top:5px;text-align: center;"
													:clearable='false' v-model="val.remark" placeholder="请输入备注" />
											</view>
										</view>
										<text class="slot-text">商品价格：
										<uni-easyinput style="width:320rpx;display: inline-block;margin-right: 10px;"
											:clearable='false' :disabled="val.isEdit" v-model="val.productPrice"
											placeholder="请输入商品价格" @change="selCount(val)" />
										</text>
										<text class="slot-text">
											商品规格：
											<template v-if="val.sendType == '40'">
												<span
													v-for="(item, index) in val.productAttr && ((val.productAttr.split(';')).splice(0, 2))"
													:key="index">
													{{ item.split(":")[0] + ':' }}
													<uni-tag :inverted="true" :text='item.split(" :")[1]'
														type="primary" />
												</span>
												<span style="display: block;margin: 2px 0px;line-height: 60rpx;">颜 色：<uni-tag
														style="margin: 0 2px;" :key="_index"
														v-for="(cor,_index) in val.colorList"
														@click="tagClick(val, cor)" :inverted="false" :text="cor.color"
														:type="cor.check && 'primary'"></uni-tag></span>
											</template>
											<span v-else>{{val.productAttr}}</span>
										</text>
										<text class="slot-text" v-if="val.productSku">商品编码：{{val.productSku}}</text>
										<text class="slot-text">购买数量：{{val.totalNum}}</text>
										<text class="slot-text">总 价：￥{{val.totalPrice}}</text>
										<text class="slot-text">已发货数量：{{val.deliveryNum}}</text>
										<text class="slot-text">发货金额：￥{{val.deliveryAmount || '0.00'}}</text>

									</view>
								</view>
								<view style="display: inline-grid;gap: 10px;">
									<!-- val.sendType == 30 || val.sendType == 40 -->
									<uni-icons v-if="orderProduct && orderProduct.length > 1" style="color: red;"
										type="trash" size="30" @click="delRow(val)"></uni-icons>
									<view v-else style="display: flex;gap: 10px;flex-direction: column;">
										<!-- <uni-tag style="display: inline-block;" text="超量发货" @click="copyRow(val, '30')"
											type="warning" /> -->
										<!-- <uni-tag style="display: inline-block;" v-if="val.skuNum > 1" text="超规格发货" @click="copyRow(val, '40')"
											type="primary" /> -->
									</view>

								</view>

							</template>

						</uni-list-item>
					</uni-list>


				</uni-section>

				<br />
				<view class="button-group">
					<button type="primary" size="mini" :loading="saveLoading" @click="addSave()">提交</button>
				</view>
			</view>
		</view>
		<!-- 选中新商品 -->
		<view class="popup-goods-box" v-if="isShowAdd" style="margin-top: 65px;">
			<uni-section title="选择商品" type="line">
				<template v-slot:right>
					<view style="display: flex;">
						<!-- 选择 -->
						<uni-easyinput prefixIcon="search" v-model="baseFormData.productName" placeholder="请搜索商品名称">
						</uni-easyinput>
						<uni-icons style="color: #077840;" type="checkmarkempty" class="icons-text" size="35"
							@click="selAddGoods"></uni-icons>
					</view>
				</template>
				<uni-card :isFull="true">
					<template v-slot>
						<mescroll-body bottom-offset="20" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
							:up="upOption" height="20" style="min-height: 0;">
						<view class="popup-content" v-for="val in spList" :key="val.id">
							<view class="popup-content-left">
								<checkbox-group @change="($event)=>checkboxChange($event,val)">
								<!-- val.stockNum == 0 || -->
									<checkbox :disabled="val.disabled" :checked="val.check" />
								</checkbox-group>
								<view class="popup-box-custom-cover">
									<image class="popup-box-cover-image" mode="aspectFill" :src="val.imagePath">
									</image>
								</view>
								<view class="popup-content-text">
									<text>商品名称：{{val.productName}}</text>
									<text>品种：{{val.categoryParentName}}</text>
									<text>分类：{{val.categoryName}}</text>
									<text>规格：<span>{{val.sku}}</span></text>
									<text>库存：{{val.stockNum}}</text>
									<text>定金比例：{{val.depositRatio}}</text>
									<text>优惠金额：￥{{val.couponPrice || '0.00'}}</text>
									<text>种植基地：{{val.produceAddressTxt}}</text>
								</view>
							</view>
		
						</view>
						</mescroll-body>
					</template>
				</uni-card>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				// 发货
				orderFrom: {},
				orderProduct: [],
				saveLoading: false,
				isShowAdd:false,
				isShowAll:true,
				orderProductTypeList:[
					  {
					 text : '销售',
					  value: 10
					},
					{
					  text: '赠品',
					  value: 20
					},
					{
					  text: '赔付',
					  value: 30
					}
				],
				downOption: {
					use: false,
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					auto: false, // 不自动加载
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 空空如也 ~', // 提示
						icon: '/static/home/saber.png'
					},
					textNoMore: '—— 没有更多了 ——'
				},
				// 发货人
				deliveryUserNameRange: [],
				deliveryTypeRange: [{
					name: '门店自提',
					value: 20
				}, ],
				items: [{
						value: '1',
						name: '全部发货'
					},
					{
						value: '2',
						name: '部分发货',

					},
				],
				current: 0,
				courierNumber: '',
				courierCompany: '',
				status: 4,
				array: [],
				index: 0,
				spList:[],
				YLproductList:[],
				express_order: '',
				value1: '',
				order_id: '',
				expressOption: [],
				baseFormData:{
					productName:''
				},
				diliform: {
					allDelivery: true,
					expressId: '',
					expressNo: '',
					orderId: '',
					productList: []
				},
				orderType: 0, //订单类型
				isClickRow: false
			}
		},
		onLoad: function(option) {
			this.order_id = option.orderId
			// this.getCourier(option.orderId)
			this.toDeliveryFun();
		},
		watch:{
			"baseFormData.productName":{
				handler(v) {
					this.productPageSkuFun();
				},
				deep:true,
			}
		},
		methods: {
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				console.log(page,'page')
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size;
				const $this = this
				this.api.productPageSku({
					pageIndex: pageNum,
					pageSize,
					// productType:1 // 普通商品 1
				}).then(res => {
					const {
						code,
						data
					} = res.data;
					console.log(data, 'data.records')
					if (page.num == 1) this.spList = [];
					const totalCount = data.total
					const orderLength = data.records.length
					// if (data.records) {
						data.records.map(val => {
							val['value'] = val.userId
							val['text'] = val.realName
							val['check'] = false;
						})
						// this.spList = data.records;
						this.spList = this.spList.concat(data.records);
						this.mescroll.endBySize(orderLength, totalCount);
						// 回显选中的
						if (this.orderProduct && this.orderProduct.length) {
							this.spList.map(val => {
								if ((this.orderProduct.map(item => item.productSkuId)).includes(val
										.productSkuId)) {
									// val['check']= true
									val['disabled'] = true;
								}
							})
						}
					// }
					// if (data.productList && data.productList.records) {
					// 	data.productList.records.map(val => {
					// 		val['value'] = val.userId
					// 		val['text'] = val.realName
					// 		val['check'] = false;
					// 	})
					// 	this.spList = data.productList.records;
					// }
				}).catch(e=>{
					this.mescroll.endSuccess()
				})
			},
		
			// 新增商品
			async addGoods() {
				await this.productPageSkuFun();
				// this.$refs.popupGoods.open()
				this.isShowAll = false;
				this.isShowAdd = true;
			
			},
			checkboxChange(e, row) {
				// if (row.stockNum == 0 && !row.check) {
				// 	row.check = false;
				// 	this.tui.toast('该商品库存不足!')
				// 	return;
				// } else {
					row.check = !row.check;
					if (row.check && !row.buyNum) {
						row.buyNum = row.minBuyCount
					}
				// }
			
				// 选中之后选中规格
				// if (row.check) {
				// 	await this.skuList(row, row.productId);
				// }
			},
			// 选择新商品
			selAddGoods() {
				console.log(this.spList.filter(val => val.check), '选中的商品');
				let SelctProduct = this.spList.filter(val => val.check);
				this.orderProduct = this.orderProduct.concat(SelctProduct);
				// this.$refs.popupGoods.close()
				this.isShowAll = true;
				this.isShowAdd = false;
				//计算接口
				// this.$nextTick(() => {
				// 	this.orderModifyCalc();
				// })
			},
			// 获取商品
			productPageSkuFun() {
				// productLists 
				this.api.productPageSku({
					pageIndex: 1,
					pageSize: 10,
					productName:this.baseFormData.productName
					// productType:1 // 普通商品 1
				}).then(res => {
					const {
						code,
						data
					} = res.data;
					console.log(data, 'data.records')
					this.spList = [];
					if (data.records) {
						data.records.map(val => {
							val['value'] = val.userId
							val['text'] = val.realName
						})
						this.spList = data.records;
						// 回显选中的
						if (this.orderProduct && this.orderProduct.length) {
							this.spList.map(val => {
								if ((this.orderProduct.map(item => item.productSkuId)).includes(val
										.productSkuId)) {
									// val['check']= true
									val['disabled'] = true;
								}
							})
						}
					}
			
				})
			},
			// 修改数量计算金额
			selCount(row) {
				let obj = {}
				if(row.orderProductId){
					obj = {
					orderProductId: row.orderProductId,
					productSkuId: row.productSkuId,
					deliveryNum: row.deliveryCount,
					productPrice:row.productPrice,
					specType: row.sendType ||  row.specType,
					orderProductType:row.orderProductType
				}
				}else{
					obj = {
						productId: row.productId,
						productSkuId: row.productSkuId,
						deliveryNum: row.deliveryCount,
						specType: row.sendType ||  row.specType,
						orderProductType:row.orderProductType
					}
				}
				this.api.deliveryCalc(obj, true).then(res => {
					console.log(res, 'res')
					const {
						code,
						data
					} = res.data;
					row['deliveryAmount'] = data || 0;
					// 计算总金额
					let Count = 0;
					this.orderProduct.map(val => {
						Count += Number(val.deliveryAmount || '');
					})
					this.orderFrom['deliveryBeforeAmount'] = Number(Count).toFixed(2)
					// this.orderFrom.deliveryTotalAmount = Count - Number(this.orderFrom.depositOutAmount || 0);
					// if (this.orderFrom.deliveryTotalAmount >= Number(this.orderFrom.depositOutAmount)) {
					//   this.orderFrom.deliveryTotalAmount = this.orderFrom.deliveryTotalAmount - this.orderFrom.depositOutAmount;
					//   this.orderFrom['depositOutPrice'] = this.orderFrom.depositOutAmount;
					// } else {
					//   this.orderFrom['depositOutPrice'] = this.orderFrom.deliveryTotalAmount
					//   this.orderFrom.deliveryTotalAmount = 0;
					// }
					 if (Count >= Number(this.orderFrom.depositOutAmount)) {
					  // 本次发货总金额(按钮左边的数字) = 列表的发货金额累加 - 定金补位(下单生成的)
					  this.orderFrom.deliveryTotalAmount = (Count - Number(this.orderFrom.depositOutAmount || 0)).toFixed(2);
					  // 本次补位余额 还是等于 定金补位(下单生成的)
					  this.orderFrom.depositOutPrice = this.orderFrom.depositOutAmount;
					} else {
					  // 否则如果 定金补位(下单生成的) 大于 列表的发货金额累加
					  // 本次补位余额 等于 列表的发货金额累加 - 定金补位(下单生成的)
					  this.orderFrom.depositOutPrice = Count;
					  // 本次发货总金额(按钮左边的数字) = 0
					  this.orderFrom.deliveryTotalAmount = 0;
					}
					
					
					this.orderFrom = JSON.parse(JSON.stringify(this.orderFrom))
					console.log(this.orderFrom.deliveryTotalAmount, 'Count')
				}).catch(e => {})
			},
			addSave() {
				// 暂时取消
				if (this.orderProduct.some(val => !val.orderProductType)) {
					return this.tui.toast('请完善商品类型在提交')
				}
				let obj = {
					orderId: this.orderFrom.orderId,
					deliveryNo: this.orderFrom.deliveryNo,
					depositOutPrice:this.orderFrom['depositOutPrice'],
					deliveryTotalAmount: this.orderFrom.deliveryTotalAmount,
					productList: this.orderProduct
				}
				console.log(obj, 'obj')
				this.saveLoading = true;
				this.api.deliveryV2(obj,true).then(res => {
					const {
						code,
						data
					} = res.data;
					console.log(res.data,'res.data')
					this.saveLoading = false;
					if (code == 1) {
						this.tui.toast('发货成功')
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/orderList/orderList'
							})
						},1000)
					}
				})
			},
			tagClick(row, cor) {
				row.colorList.map(val => val.check = false)
				cor.check = !cor.check;
				if (cor.check) {
					row.productSkuId = cor.productSkuId
					row.productAttr = cor.productAttr
				}
			},
			// 前端删除
			delRow(row) {
				const set1 = new Set([row].map(item => item['productSkuId']))
				const set2 = new Set(this.orderProduct.map(item => item['productSkuId']))
				const diff = [
					...[row].filter(item => !set2.has(item['productSkuId'])),
					...this.orderProduct.filter(item => !set1.has(item['productSkuId']))
				]
				this.orderProduct = diff;
				 this.orderProduct.map(order => {
				if (order.orderProductId == row.orderProductId && (!order.sendType || order.sendType == '20')) {
				  order.deliveryCount = 0;
				  order.isEdit = false;
				}
			  })
			  this.orderProduct = JSON.parse(JSON.stringify(this.orderProduct))
			  // 点击了超规格就计算一次
			  setTimeout(()=>{
				row.deliveryCount = 0
			  	this.selCount(row) // 计算新的
			  },500)
			},
			// 超量超规格发货
			async copyRow(row, type) {
				if(row.isEdit){
					return
				}
				// sendType "正常发货" type:20 "超量发货" type:30 "超规格发货" type:40
				this.isClickRow = true
				let _row = JSON.parse(JSON.stringify(row))
				_row['rowID'] = this.generateRandomLetterArray();
				_row['sendType'] = type;
				// 超规格
				if (type == '40') {
					await this.skuList(_row, row.productId);
				}
				this.orderProduct.push(_row);
				// 点击了超规格 置空原商品购买数量为0 
				  this.orderProduct.map(order => {
					if (order.orderProductId == row.orderProductId && (!order.sendType || order.sendType == '20')) {
					  order.deliveryCount = 0;
					  order.deliveryAmount = 0;
					  order.isEdit = true;
					}
				  })
				  // 点击了超规格就计算一次
				  setTimeout(()=>{
					  this.selCount(_row) // 计算新的
				  },500)
				  // this.orderProduct = JSON.parse(JSON.stringify(this.orderProduct))
			},
			// 获取规格
			skuList(_row, productId) {
				this.api.skuList({
					productId
				}).then(res => {
					const {
						code,
						data
					} = res.data;
					console.log(data, 'data-----')
					_row['colorList'] = data
					//默认选择第一个
					_row['colorList'][0]['check'] = true;
					_row['productSkuId'] = data[0]['productSkuId']
					this.orderProduct = JSON.parse(JSON.stringify(this.orderProduct))

				})
			},
			// 发货详情
			toDeliveryFun() {
				let Params = {
					orderId: this.order_id
				}
				this.api.toDelivery(Params).then(res => {
					console.log(res, 'res++++')
					const {
						code,
						data
					} = res.data;
					if (code == 1) {
						const {
							order,
							orderProduct,
							deliveryNo,
							deliveryTime,
							deliveryType,
							deliveryUserName,
							deliveryUserId
						} = data;
						this.orderFrom = {
							...order,
							deliveryNo,
							deliveryTime,
							deliveryType,
							deliveryUserName,
							deliveryUserId
						};
						this.orderProduct = orderProduct;
						this.orderProduct.map(val => {
							// val['deliveryCount'] = val.totalNum;
							val['deliveryCount'] = 0
							val['isEdit'] = false;
							val['rowID'] = this.generateRandomLetterArray();
						})
						console.log(this.orderProduct, 'this.orderProduct')
					}
				})
			},
			// 前端随机生成id
			getRandomLetter() {
				const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
				return letters.charAt(Math.floor(Math.random() * letters.length));
			},

			generateRandomLetterArray(length = 10) {
				const randomLetterArray = [];
				for (let i = 0; i < length; i++) {
					randomLetterArray.push(this.getRandomLetter());
				}
				return randomLetterArray.join("");
			},
			bindPickers(item, index) {
				if (!item.length) {

				} else {
					return item[index].value
				}
			},
			// 单选按钮点击事件
			radioChange: function(evt) {
				const value = Number(evt.target.value)
				this.diliform.allDelivery = (value === 1 ? true : false)
			},
			// 获取快递公司
			getCourier(id) {
				const $this = this
				$this.diliform.orderId = parseInt(id)
				uni.showLoading({

				})
				this.api.toDelivery({
						orderId: id
					})
					.then(res => {
						uni.hideLoading()
						const serverData = res.data
						if (serverData) {
							const {
								code,
								data
							} = serverData
							if (code === 1) {
								$this.expressList = data.expressList
								$this.orderProduct = data.orderProduct
									.map(d => {
										return {
											productName: d.productName,
											productAttr: d.productAttr,
											num: 0,
											productId: d.orderProductId,
											sysl: Number(d.totalNum) - Number(d.deliveryNum)
										}
									})
								$this.orderType = data.order.deliveryType
								//console.log('bbb', $this.orderProduct)
								$this.array = data.expressList.map(f => {
									return {
										value: f.expressName,
										id: f.expressId
									}
								})
								if ($this.array && $this.array.length > 0) {
									//设置默认的快递信息
									$this.diliform.expressId = $this.array[0].id

								}
							}
						}
						console.log('res', res)
					}).catch(err => {
						uni.hideLoading()
					})
			},
			bindPickerChange: function(e) {
				const value = e.target.value
				//设置发货的快递
				const item = this.array[value]
				if (item) {
					this.diliform.expressId = item.id
					this.index = value
				}

			},
			submit: function() {
				const $this = this

				if ($this.orderType !== 20) {
					if (!this.express_order) {
						uni.showToast({
							title: '请填写快递单号',
							icon: 'none',
							duration: 1000
						});
						return
					}
					if (!this.diliform.expressId) {
						uni.showToast({
							title: '请选择快递公司',
							icon: 'none',
							duration: 1000
						});
						return
					}
				}

				//组合数据
				$this.diliform.expressNo = $this.express_order
				let isBreak = false;
				let pdModel = {}

				const productJson = []
				if (!$this.diliform.allDelivery) {
					//组合部分商品发货信息
					const products = $this.orderProduct
					for (let i = 0; i < products.length; i++) {
						const product = products[i]
						if (parseInt(product.num) > product.sysl) {
							isBreak = true
							pdModel = product
							break
						} else if (parseInt(product.num) <= 0) {
							pdModel = product
							isBreak = true
						}
						productJson.push({
							orderProductId: product.productId,
							deliveryCount: parseInt(product.num)
						})
					}

				}
				if (isBreak) {
					$this.tui.toast(`${pdModel.productName}的发货数量不合法`)
				} else {
					$this.diliform.productList = productJson
					uni.showLoading({
						title: '请稍后....'
					})
					// 全部发货
					this.api.confirmDelivery($this.diliform)
						.then(res => {
							const {
								code,
								msg
							} = res.data

							if (code === 1) {
								$this.tui.toast('发货成功')
								uni.$emit('detailStatus')
								setTimeout(() => {
									uni.switchTab({
										url: '/pages/orderList/orderList',
									})
								}, 900)

							} else {
								$this.tui.toast(msg)
							}
							uni.hideLoading()
						}).catch(err => {
							uni.hideLoading()
							$this.tui.toast('发货异常')
						})
				}
			}
		}
	}
</script>
<style scoped>
	/deep/.uni-forms-item{
		margin-bottom: 10rpx!important;
	}
	/deep/.uni-easyinput__content-input,.uni-date__x-input{
		color: #333!important;
	}
	/deep/.popup-goods-box .uni-section .uni-section-header{
		position: fixed;top: 45px;z-index: 2000;width: 95%;background: #fff;
	}
	.popup-goods-box .uni-section .uni-section-content{
		margin-top: 60px;
	}
	
</style>

<style lang="less" scoped>
	.delivery-courier {
		background: #F9F9F9;
	}

.popup-content-text {
		uni-text {
			display: block;
			// width: 540rpx;
			white-space: pre-wrap;
			word-wrap: break-word;
		}
	}
.popup-content {
		margin: 5px 0;
		border-bottom: 1px solid #077840;
	}

	.sel-popup-content {
		border-bottom: none;
		box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.18);
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
	}

	.button-group {
		position: fixed;
		bottom: 0;
		/* left: 40%; */
		width: 100%;
		background: #fff;
		padding-top: 10px;
	}

	.slot-box {
		display: flex;
		align-items: center;
		gap: 20rpx;
		color: #606266;
		font-size: 28rpx;

		.slot-box-left {
			width: 100rpx;
			height: 100rpx;

			img {
				width: 100rpx;
				height: 100rpx;
			}
		}

		.slot-box-right {
			display: flex;
			flex-wrap: wrap;

			.slot-text {
				display: block;
				width: 100%;
				margin: 3px 0px;
			}
		}
	}

	.split-line {
		width: 100%;
		height: 20rpx;
		background-color: #F9F9F9;
	}

	.courier-number {
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		padding-left: 30rpx;
		line-height: 100rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		margin-bottom: 10rpx;

		.radio-group {
			display: inline-block;

			view {
				display: inline-block;

			}

			.radio {
				margin-left: 30rpx;
			}

			.name {
				margin-right: 50rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}
	}

	.courier-box {
		width: 100%;
		height: 200rpx;
		background: #FFFFFF;

		.courier {
			display: flex;
			width: 690rpx;
			margin: 0 auto;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #999999;

			input {
				height: 100rpx;
				margin-left: 20rpx;
				color: #333333;

				.input-placeholder {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}
		}

		.order-num {

			border-bottom: 2px solid #EEEEEE;
			box-sizing: border-box;
		}
	}

	.next-btn {
		width: 630rpx;
		height: 96rpx;
		background: #077840;
		border-radius: 8rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		line-height: 96rpx;
		text-align: center;
		color: #fff;
		font-size: 32rpx;
		font-weight: 500;
	}

	.comp {
		margin-right: 22rpx;
	}

	.goods_detail {
		padding: 0 30rpx;

		.goods_detail_item {
			// width: 100%;
			display: flex;
			padding: 30rpx;
			flex-direction: column;
			background: #FFFFFF;

			.goods_detail_item_order_title {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 40rpx;
			}

			.goods_detail_item_gooods_name {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 40rpx;
				margin-top: 20rpx;
			}

			.goods_detail_item_shipments_number {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 40rpx;
				margin-top: 40rpx;

			}

			.goods_detail_item_shipments_import {
				height: 50rpx;
				padding-bottom: 10rpx;
				border-bottom: 2rpx solid #EEEEEE;
				margin-top: 20rpx;
			}

			.goods_detail_item_extra {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 40rpx;
				margin-top: 40rpx;

			}

			.goods_detail_item_extra_number {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 40rpx;
				margin-top: 20rpx;

			}
		}
	}
</style>